package com.advertise.tool;



import javax.servlet.ServletOutputStream;


import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.util.ValueStack;

public class XMLResult implements Result {

	
	private String exposedValue;
	
	
	public String getExposedValue() {
		return exposedValue;
	}


	public void setExposedValue(String exposedValue) {
		this.exposedValue = exposedValue;
	}


public void execute(ActionInvocation invocation) throws Exception {
		
		ValueStack stack=ActionContext.getContext().getValueStack();
		try{
			HttpServletResponse response=ServletActionContext.getResponse();
			
			response.setContentType("text/xml;charset=UTF-8");
			
			 ServletOutputStream outStream=response.getOutputStream();
			 
			 Object result=invocation.getAction();
			
			if(exposedValue != null){
				result=stack.findValue(exposedValue);
			}		
			
			outStream.write(result.toString().getBytes("UTF-8"));		
			
			
			outStream.flush();
		}
		catch (Exception e) {
			e.printStackTrace();
		}

	}


}
